package com.hzy.base;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;

import java.util.List;

/**
 * Created by hongzhiyuanzj on 2019/3/29.
 */
public class PersistenceFactory extends SqlSessionDaoSupport{

    private PlatformTransactionManager transactionManager;

    public void setPlatformTransactionManager(PlatformTransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }

    public int insert(String sqlMapperID, Object obj) {
        return this.getSqlSession().insert(sqlMapperID, obj);
    }

    public int update(String sqlMapperID, Object obj) {
        return this.getSqlSession().update(sqlMapperID, obj);
    }

    public int delete(String sqlMapperID, Object obj) {
        return this.getSqlSession().delete(sqlMapperID, obj);
    }

    public <T> T selectOne(String sqlMapperID, Object obj) {
        return this.getSqlSession().selectOne(sqlMapperID, obj);
    }

    public <T> T selectOne(String sqlMapperID) {
        return this.getSqlSession().selectOne(sqlMapperID);
    }

    public <T> List<T> selectList(String sqlMapperID, Object obj) {
        return this.getSqlSession().selectList(sqlMapperID, obj);
    }

    public <T> List<T> selectList(String sqlMapperID) {
        return this.getSqlSession().selectList(sqlMapperID);
    }

    public void commit(TransactionStatus transactionStatus) {
        this.transactionManager.commit(transactionStatus);
    }

    public void rollback(TransactionStatus transactionStatus) {
        this.transactionManager.rollback(transactionStatus);
    }

}
